using System;
using System.Configuration;

namespace LocalBoard.Web
{
	/// <summary>
	/// Summary description for ClubSecurePage.
	/// </summary>
	public class ClubSecurePage : System.Web.UI.Page
	{
		private bool _allowAnonymousUser = false;
		public bool AllowAnonymousUser
		{
			get {return _allowAnonymousUser;}
		}

		public ClubSecurePage()
		{
			try
			{
				_allowAnonymousUser = bool.Parse(ConfigurationSettings.AppSettings["AllowAnonymousUser"]);
			}
			catch
			{}
		}

		public new ClubPrincipal User
		{
			get {return base.User as ClubPrincipal;}
		}

		protected override void OnInit(EventArgs e)
		{
			if(Request.IsAuthenticated)
			{
				if(User.UserProfile == null)
					Response.Redirect("Register.aspx");
			}
			else if(!_allowAnonymousUser)
			{
				Response.Redirect("Login.aspx");
			}
		}
	}
}
